/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */

package br.ufmg.dees.insane.ui.rich.learn.learn_view;
import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.util.ArrayList;

/**
 * A class representing the state of the view.
 * @author	Penna, Samuel & Pitangueira, Roque
 * @see     xyplot_view.InterfaceXYPlot
 * @see     xyplot_view.DrawingArea
 * @since   april 2005
 */
public class ViewState implements Serializable {
	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;
	
    //The colors of the drawing model    
	public Color pointColor = Color.BLACK;
	public Color controlPointColor = Color.BLUE;
	public Color previewElementColor = Color.BLUE;
    public Color lineColor = Color.BLACK;
	public Color regionColor = new Color(255, 255, 220);
	public Color curveColor = Color.MAGENTA;
	public Color parelementColor = new Color(255, 255, 200);
	public Color boundaryColor = Color.BLUE;
	public Color boundaryElementColor = Color.BLACK;
    public Color markColor = Color.ORANGE;
	public Color divisionNodeColor = Color.RED;
	public Color supportColor = Color.BLACK;
	public Color springColor = Color.BLACK;
    public Color loadColor = Color.BLUE;
    public Color distributedLoadColor = Color.BLUE;
	public Color concForcePointColor = new Color(153, 0, 0);
	public Color displaceColor = new Color (153, 102, 0);
    public Color preStrainsColor = new Color(0, 102, 51);
	public Color iniEqForceColor = new Color(255, 102, 0);
	public Color reactionsColor = Color.RED;
	public Color equationsColor = Color.RED;
	public Color tempChangeColor = Color.RED;
	public Color globalAxisColor = Color.BLACK;
	public Color localAxisColor = Color.MAGENTA;
	public Color deformColor = new Color(102, 102, 0);
	public Color fxDiagramColor = Color.RED;
	public Color fyDiagramColor = new Color(0, 102, 51);
	public Color fzDiagramColor = Color.PINK;
	public Color mxDiagramColor = Color.ORANGE;
	public Color myDiagramColor = Color.MAGENTA;
	public Color mzDiagramColor = Color.BLUE;
	public Color dxDiagramColor = new Color(102, 102, 0);
	public Color dyDiagramColor = new Color(102, 102, 0);
	public Color dzDiagramColor = new Color(102, 102, 0);
	public Color rxDiagramColor = new Color(102, 102, 0);
	public Color ryDiagramColor = new Color(102, 102, 0);
	public Color rzDiagramColor = new Color(102, 102, 0);
	
	//the model file path
	private String name = new String("untitled.isn");
    private transient String path = new String();
    
//  The scales
    public double loadScale = 1;
    public double supportScale = 1;
    public double nodeScale = 4;
	public double displaceScale = 1;
    public double deformScale = 1;
    public double diagramScale = 1;
	public double concForcePointScale = 4;
	public double preStrainsScale = 0.5;
	public double iniEqForceScale = 1;
	public double reactionsScale = 1;
	
	    
    //  The number view precision
    private int precision = 1;

    //  The limits of the view
    private double vx = 0;
    private double vy = 0;
    private double vwidth = 10;
    private double vheight = 10;
    
    //The Current zoom of the view
    private double zx = 0;
    private double zy = 0;
    private double zwidth = 10;
    private double zheight = 10;

    //The limits and increments of the grid
    private double gx = 1;
    private double gy = 1;
    private double gwidth = 10;
    private double gheight = 10; 
    private double gxInc = 1;
    private double gyInc = 1;
    
    //The snap and grid existence
    private boolean snap = false;
    private boolean grid = true;
    
    //  The view background color
    public Color bgcolor   = Color.WHITE;    

    //The grid color
    public Color gridColor = Color.darkGray; 
    
    private boolean viewGlobalAxis = true;
	private boolean viewLocalAxis = false;
	private boolean viewNodeLabel = true;
	private boolean viewElementLabel = true;
	private boolean viewRegionLabel = true;
	
	private ArrayList<Color> colors = new ArrayList<Color>();
    
//  *****************************************************************************

    public ViewState() {
    }
    
//  *****************************************************************************    
 
    public void setName(String s) {
        String ext = new String();
        int i = s.lastIndexOf('.');
        if (i > 0 &&  i < s.length() - 1) {
                ext = s.substring(i+1).toLowerCase();
        }
        if (!ext.equals("isn")){
                s = s + ".isn";
        }
        name = s;
    }
    
//*****************************************************************************
	
    public String getName() {
        return name;
    }
    
    /**
     * @param s
     */
    public void setPath(String s) {
        path = s;
    }
    
    /**
     * @return
     */
    public String getPath() {
        return path;
    }
//  *****************************************************************************    
 
    /**
     * @param i
     */
    public void setPrecision(int i) {
        precision = i;
    }
	
    /**
     * @return
     */
    public int getPrecision() {
        return precision;
    }
//  *****************************************************************************
  
    /**
     * @param lim
     */
    public void setLimits(Rectangle2D lim) {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.setRect(lim);
        vx = limits.x;
        vy = limits.y;
        vwidth = limits.width;
        vheight = limits.height;
    }
    
    /**
     * @param x
     * @param y
     */
    public void setLimits(double x, double y) {
        this.vx = 0.0;
        this.vy = 0.0;
        vwidth = x;
        vheight = y;
    }
	
    /**
     * @return
     */
    public Rectangle2D.Double getLimits() {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.x = vx;
        limits.y = vy;
        limits.width = vwidth;
        limits.height = vheight;
		return limits;
    }
    
//  *****************************************************************************    
  
    /**
     * @param lim
     */
    public void setCurrentZoom(Rectangle2D lim) {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.setRect(lim);
        zx = limits.x;
        zy = limits.y;
        zwidth = limits.width;
        zheight = limits.height;
    }
    
	
    /**
     * @return
     */
    public Rectangle2D.Double getCurrentZoom() {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.x = zx;
        limits.y = zy;
        limits.width = zwidth;
        limits.height = zheight;
        return limits;
    }
//  *****************************************************************************   
   
    /**
     * @param is_on
     */
    public void setGrid(boolean is_on) {
        grid = is_on;
    }
    
    /**
     * @return
     */
    public boolean isGridOn() {
        return grid;
    }
//  *****************************************************************************
  
    /**
     * @param lim
     */
    public void setGridLimits(Rectangle2D lim) {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.setRect(lim);
        gx = limits.x;
        gy = limits.y;
        gwidth = limits.width;
        gheight = limits.height;
    }
    
    /**
     * @return
     */
    public Rectangle2D.Double getGridLimits() {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.x = gx;
        limits.y = gy;
        limits.width = gwidth;
        limits.height = gheight;
        return limits;
    }
//  *****************************************************************************   
  
    /**
     * @param x
     * @param y
     */
    public void setGridIncrements(double x, double y) {
        gxInc = x;
        gyInc = y;
    }
//  *****************************************************************************   
  
    /**
     * @return
     */
    public double getGridXInc() {
        return gxInc;
    }
    
    /**
     * @return
     */
    public double getGridYInc() {
        return gyInc;
    }
//  *****************************************************************************   
  
    /**
     * @param b
     */
    public void setSnap(boolean b) {
        snap = b;
    }
    
    /**
     * @return
     */
    public boolean isSnapOn() {
        return snap;
    }

//  ***************************************************************************** 
    /**
     * The setViewGlobalAxis method
     */
    public void setViewGlobalAxis(boolean b) {
        viewGlobalAxis = b;
    }
    
//*****************************************************************************
	
    /**
     * The getViewGlobalAxis method
     */
    public boolean getViewGlobalAxis() {
        return viewGlobalAxis;
    }
	
//*****************************************************************************
	
    /**
     * The setViewLocalAxis method
     */
    public void setViewLocalAxis(boolean b) {
        viewLocalAxis = b;
    }
    
//*****************************************************************************
	
    /**
     * The getViewLocalAxis method
     */
    public boolean getViewLocalAxis() {
        return viewLocalAxis;
    }
	
//*****************************************************************************
    /**
     * Returns the Background color.
     * @return The current background color
     */
    public Color getBackground() {
        return bgcolor;
    }
    
    
//  *****************************************************************************
    
//  *****************************************************************************
	
    /**
     * The getViewNodeLabel method
     */
    public boolean getViewNodeLabel() {
        return viewNodeLabel;
    }
	
//*****************************************************************************
	
	/**
	 * Sets the viewElementLabel variable.
	 * @param  sl The desired variable to be set.
	 */
	public void setViewElementLabel(boolean sl) {
		viewElementLabel = sl;
	}
	
//*****************************************************************************
	
	/**
	 * Returns the viewElementLabel variable.
	 * @return The current viewElementLabel value.
	 */
	public boolean getViewElementLabel() {
		return viewElementLabel;
	}
	
//*****************************************************************************
	
    /**
     * The setViewRegionLabel method
     */
    public void setViewRegionLabel(boolean b) {
        viewRegionLabel = b;
    }
    
//*****************************************************************************
	
    /**
     * The getViewRegionLabel method
     */
    public boolean getViewRegionLabel() {
        return viewRegionLabel;
    }
	
//*****************************************************************************
    /**
	 * Returns the element color at the specified position in this list.
	 * @return The element color at the specified position in this list.
	 */
	public Color getColor(int index) {
		while ( colors.size()<=index ) {
			float r = (float)Math.random();
			if (r < 0.5) r = r + (float)0.5;
			float g = (float)Math.random();
			if (g < 0.5) g = g + (float)0.5;
			float b = (float)Math.random();
			if (b < 0.5) b = b + (float)0.5;
			colors.add( new Color(r, g, b) );
		}
		return (Color)colors.get(index);
	}

	

	public void setBackground(Color bgcolor) {
		this.bgcolor = bgcolor;
	}
    }

